package oop2;

/**
 * @author oldliu
 * @since 1.0
 */
public class JavaClass {
    public String name;
    public String dirTeacher;
    String manageTeacher;
    String startDate;
    //班级的学生
    String names[] = new String[30];
    //int count=0;//
    //String ids[]=new String[30];
    // String phones[]=new String[30];
    //介绍一下班级情况
    public void selfIntro() {
        System.out.println("这是" + name);
        System.out.println("指导老师" + dirTeacher);
        System.out.println("班主任" + manageTeacher);
        System.out.println("于" + startDate + "开班");
        System.out.println("学生信息如下：");
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null)
                break;
            System.out.print(names[i] + " ");
        }
        System.out.println();
    }

    /**
     * 新生加入班级
     */
    public void add(String newName) {
        //循环，找到数组的空位置
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null) {
                names[i] = newName;
                return;
            }
        }
        System.out.println("家人失败，没有空位子了");
    }

    //根据名字查找在不在
    public boolean search(String n) {
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null) {
                return false;
            }
            if (names[i].equals(n)) {
                return true;
            }
        }
        return false;
    }

    //按照范围查找学生
    public boolean search2(String n, int start, int end) {
        for (int i = start; i <= end && i >= 0 && end < names.length; i++) {
            if (names[i] == null) {
                return false;
            }
            if (names[i].equals(n)) {
                return true;
            }
        }
        return false;
    }
}
